package com.core.family.gen.web;


import com.core.family.gen.domain.po.TableBeanPo;
import com.core.family.gen.service.gen.IGenHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: honglei
 * @time: 2021/10/22 0022 11:11
 */
@Controller("webGenController")
@RequestMapping("/")
public class GenController {


    @Autowired
    IGenHandler generatorService;


    @RequestMapping("/genCode")
    public boolean genCode(@RequestBody List<TableBeanPo> tableNames) throws Exception {
        return generatorService.genCode(tableNames);

    }


    @RequestMapping("getInit")
    // @ResponseBody
    public Object getInit(HttpServletRequest req, Map<String, String> map) throws Exception {
//        WebGenConfig genConfig=new WebGenConfig();
//        genConfig.setBaseDirPath(map.get(""));
//        genConfig.setPackageName(map.get(""));
//        genConfig.setTablePrefix(map.get(""));
//        genConfig.setSqlType(map.get(""));
//        genConfig.setUrl(map.get(""));
//        genConfig.setUserName(map.get(""));
//        genConfig.setPassword(map.get(""));
//        generatorService.setConfig(genConfig);
//        List<TableBeanPo> list = generatorService.tablesList();
//        req.setAttribute("genConfig",genConfig);
//        req.setAttribute("list",list);
        return "/gen/index";
    }


    @RequestMapping("index")
    public String index(HttpServletRequest req) throws Exception {
//        WebGenConfig genConfig=new WebGenConfig();
//        req.setAttribute("genConfig",genConfig);
        return "/gen/index";

    }


}
